<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="model.Mesto"%>

<jsp:useBean id="mfromTown" class="model.Mesto" scope="session" />
<jsp:useBean id="mToTown" class="model.Mesto" scope="session" />
<jsp:useBean id="prevoznik" class="model.Prevoznik" scope="session" />


<html> 
<head>
<title>Red vožnje</title>
</head>
<body>
<h1>Red vožnje</h1>
<h3>Prevoznik: ${prevoznik.naziv}</h3>

<form action="/timeTableServlet" method="get">
<table>
	<tr>
		<td align="right">Od:</td>
		<td><select name="fromTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:if test="${empty mfromTown.sifra.id}">
					<option>${town.naziv}</option>
				</c:if>
				<c:if test="${not empty mfromTown.sifra.id}">
					<c:if test="${mfromTown.sifra.id == town.sifra.id}">
						<option selected="selected">${town.naziv}</option>
					</c:if>
					<c:if test="${mfromTown.sifra.id != town.sifra.id}">
						<option>${town.naziv}</option>
					</c:if>
				</c:if>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td align="right">Do:</td>
		<td><select name="toTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:if test="${empty mToTown.sifra.id}">
					<option>${town.naziv}</option>
				</c:if>
				<c:if test="${not empty mToTown.sifra.id}">
					<c:if test="${mToTown.sifra.id == town.sifra.id}">
						<option selected="selected">${town.naziv}</option>
					</c:if>
					<c:if test="${mToTown.sifra.id != town.sifra.id}">
						<option>${town.naziv}</option>
					</c:if>
				</c:if>
			</c:forEach>
		</select></td>
	</tr>
	
	<tr>
		<td><input name="showTrip" type="hidden" value="true"></td>
		<td><input type="submit" value="Prikaži"></td>
	</tr>
</table>
</form>

<table border="1">
	<tr bgcolor="lightGrey">
		<td>RB</td>
		<td>Od</td>
		<td>Do</td>
		<td>Polazak</td>
		<td>Dolazak</td>
		<td>Osnovna cena</td>
		<td>Povlastice</td>
		<td>Akcije</td>
	</tr>

	<c:forEach var="trip" items="${sessionScope.allTrips}"
		varStatus="rowCounter">
		<tr>
			<td><c:out value="${rowCounter.count}" /></td>
			<td><c:out value="${trip.mestoOd.naziv}" /></td>
			<td><c:out value="${trip.mestoDo.naziv}" /></td>
			<td><fmt:formatDate pattern="hh:mm" value="${trip.polazak}" /></td>
			<td><fmt:formatDate pattern="hh:mm" value="${trip.dolazak}" /></td>
			<td><c:out value="${trip.cena} din." /></td>
			<td><c:forEach var="povl" items="${trip.povlastica}">
				<a href="/benefits?showBenefit=true&ID=${povl.sifra.id}">${povl.naziv}</a>&nbsp;
			</c:forEach></td>
			<td><a href="/trips?showData=true&ID=${trip.sifra.id}">Pregled</a> |
			<a href="/trips?change=true&ID=${trip.sifra.id}">Izmena</a> | <a
				href="/trips?delete=true&ID=${trip.sifra.id}">Brisanje</a></td>
				
		</tr>
	</c:forEach>
</table>
<br />
<br />

<p>
<big>Dodavanje:</big>
<ul>
	<li><a href="/benefits">Povlastice</a></li>
	<li><a href="/trips">Linije</a></li>
</ul>
<br>
<br>
<a href="/logIn?logOff=true">Odjava</a>
</p>
</body>
</html>
